package com.company.OfferGuide;

import java.util.LinkedHashMap;
import java.util.Map;

public class 第一个只出现一次的字符 {

    public char firstUniqChar(String s) {
        if (s == null || s.length() == 0) return ' ';
        LinkedHashMap<Character, Integer> linkedHashMap = new LinkedHashMap<>();

        for (int i = 0; i < s.length(); i++) {
            linkedHashMap.put(s.charAt(i), linkedHashMap.getOrDefault(s.charAt(i),0) + 1);
        }

        for (Map.Entry<Character, Integer> entry : linkedHashMap.entrySet()) {
            if (entry.getValue() == 1) return entry.getKey();
        }

        return  ' ';

    }

}
